<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.Date"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="date" value="<%=new Date() %>"/> 
<fmt:formatDate var ="now" value="${date }" type="date" pattern="yyyy-MM-dd HH:mm:ss"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="/${initParam.context_root}/ckeditor/ckeditor.js"></script>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function onSendMail(){
	if($(":input[name='title']").val() ==""){
		alert("제목을 입력하세요.");
		return;
	}
	if($(":input[name='address']").val() ==""){
		alert("수신자 메일주소를 입력하세요.");
		return;
	}
	if($(":input[name='addressCC']").val() ==""){
		alert("참조 메일주소를 입력하세요.\n( 참조가 없을시 [-]로 삭제하세요.)");
		return;
	}
	var flag = window.confirm("작성한 내용으로 메일을 보내시겠습니까?");
	if(flag){
		$("#sendMail").submit();
	} else{
		return;
	}
}
function addAddressee(){
	var inputAddress = document.createElement("input");
	inputAddress.name = "address";
	inputAddress.type ="text";
	inputAddress.maxlength="30";

	var space = document.getElementById("addAddressee");
	space.appendChild(inputAddress);
}
function addCC(){
	var inputAddress = document.createElement("input");
	inputAddress.name = "addressCC";
	inputAddress.type ="text";
	inputAddress.maxlength="30";

	var space = document.getElementById("addCC");
	space.appendChild(inputAddress);
}
function subAddressee(){
	var space = document.getElementById("addAddressee");
	space.removeChild(space.lastChild);
}
function subCC(){
	var space = document.getElementById("addCC");
	space.removeChild(space.lastChild);
}
</script>
<title>메일쓰기폼</title>
</head>
<body>
<form id="sendMail" name="sendMail" action="/${initParam.context_root }/sendMail.do" method="post" enctype="multipart/form-data">
<input type="hidden" value="${now }" name="sendDate">
<br>
<div align="right" style="padding-right: 15px">
<a href="/${initParam.context_root }/typeTen.do">[목록]</a>&nbsp;&nbsp;<a href="javascript:onSendMail()">[보내기]</a>
</div>
<table border="1px" cellpadding="10px" cellspacing="0px" width="980px" height="600px">
	<tr>
		<th style="text-align: left; width: 13%; background-color: lightgray" >제목</th><td><input type="text" name="title" style="width: 700px;" maxlength="100"></td>
	</tr>
	<tr>
		<th style="text-align: left; width: 13%; background-color: lightgray" ><input type="hidden" name="type" value="수신">수신자</th>
		<td><input type="text" name="address" maxlength="30"><span id="addAddressee"></span><a href="javascript:addAddressee()">[+]</a>&nbsp;<a href="javascript:subAddressee()">[-]</a></td>
	</tr>
	<tr>
		<th style="text-align: left; width: 13%; background-color: lightgray" >참조</th>
		<td><span id="addCC"></span><a href="javascript:addCC()">[+]</a>&nbsp;<a href="javascript:subCC()">[-]</a></td>
	</tr>
	<tr>
		<th style="text-align: left; width: 13%; background-color: lightgray" >발신자</th>
		<td>
			<c:choose>
				<c:when test="${ empty sessionScope.user}"><font color="red" style="font-style: italic; text-decoration: underline; ">로그인 후 다시 접속하세요.</font></c:when>
				<c:otherwise>
					<input type="text" name="sender"  value="${sessionScope.user.id }@daou.co.kr" maxlength="30">
				</c:otherwise>
			</c:choose>
		</td>
	</tr>
	<tr>
		<th style="text-align: left; height:65%;width: 13%; background-color: lightgray" >내용</th>
		<td><textarea name="content" id="content" rows="15" cols="80" style="width: 100%; height: 400px;"></textarea>
			<script type="text/javascript">
				CKEDITOR.replace('content');
			</script>
		</td>
	</tr>
	<tr>
		<th style="text-align: left; width: 13%; background-color: lightgray" >첨부파일</th><td><input type="file" name="upfile" value="첨부파일 찾기"></td>
	</tr>
</table>
<div align="right" style="padding-right: 15px">
<a href="/${initParam.context_root }/typeTen.do">[목록]</a>&nbsp;&nbsp;<a href="javascript:onSendMail()">[보내기]</a>
</div>
</form>
</body>
</html>